﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace iSufeMVC4.Qiancun
{
    public static class  QcRegisterSerive
    {
        public static int GetTeamCount()
        {
            using (QianCunRegisterDataContext db = new QianCunRegisterDataContext())
            {
                return
                    db.TeamInfo.Where(p => p.InfoID.Trim().Length > 0).Count();
            }
        }
        public static int GetTeamUserCount()
        {
            using (QianCunRegisterDataContext db = new QianCunRegisterDataContext())
            {
                return 
                    db.TeamInfo.Where(p => p.InfoID.Trim().Length > 0).Count()
                    + db.TeamInfo.Where(p => p.Member1NO.Trim().Length > 0).Count()
                    + db.TeamInfo.Where(p => p.Member2NO.Trim().Length > 0).Count();
            }
        }

        public static TeamInfo GetTeamInfo(string StdCode)
        {
            using (QianCunRegisterDataContext db = new QianCunRegisterDataContext())
            {
                return db.TeamInfo.Where(
                    p => p.Member1NO == StdCode || 
                        p.Member2NO == StdCode || 
                        p.InfoID==StdCode)
                        .FirstOrDefault();
            }
        }

        public static string GetProvinceName(int code)
        {
            using (QianCunRegisterDataContext db = new QianCunRegisterDataContext())
            {
                return db.Info_Province.Where(p => p.ProvinceID == code).FirstOrDefault().ProvinceName.ToString();
            }
        }

        public static string GetCityName(string code)
        {
            using (QianCunRegisterDataContext db = new QianCunRegisterDataContext())
            {
                return db.Info_City.Where(p => p.CityID == code).FirstOrDefault().CityName.ToString();
            }
        }

        public static string GetAreaName(string code)
        {
            using (QianCunRegisterDataContext db = new QianCunRegisterDataContext())
            {
                return db.Info_Area.Where(p => p.AreaID == code).FirstOrDefault().AreaName.ToString();
            }
        }

        public static int GetTeamCountByCollege(string Code)
        {
            using (QianCunRegisterDataContext db = new QianCunRegisterDataContext())
            {
                return db.MUserInfo.Where(p => p.UserCollege == Code).ToList().Count;
            }
        }
    }
}
